package com.adou.multi.multi_tenancy.page;

import java.util.List;

import lombok.Data;

@Data
public class PageResult<T> extends BasePage {
	// private int pageNumber;
	// private int pageSize;
	private int totalPage;
	private int totalElements;
	private List<T> content;

	public PageResult() {
	}

	public PageResult(int pageNumber, int pageSize) {
		setPageNumber(pageNumber);
		setPageSize(pageSize);
	}

	public PageResult(Integer pageNumber, Integer pageSize, Integer totalElements, List<T> content) {
		this(pageNumber, pageSize);
		this.totalElements = totalElements == null ? 0 : totalElements;
		this.content = content;

		if (this.pageSize != 0) {
			if (totalElements % pageSize == 0) {
				this.totalPage = (totalElements / pageSize);
			} else {
				this.totalPage = ((totalElements / pageSize) + 1);
			}
		}
	}

	public void setTotalElemnts(Long totalElements) {
		this.totalElements = totalElements == null ? 0 : totalElements.intValue();
		if (this.totalPage != 0) {
			this.totalPage = totalElements.intValue() / this.pageSize;
		}
	}

	public static PageResult buitDefaultPage() {
		return new PageResult<>();
	}

	public boolean haseContent() {
		return content != null && (this.content.isEmpty());
	}

}
